package com.example.crmweb.controller;


import com.example.crmweb.entity.Staff;
import com.example.crmweb.service.StaffService;
import com.example.crmweb.lang.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author -CRM-
 * @since 2022-03-18
 */
@RestController
@RequestMapping("/staff")
public class StaffController {
    @Resource
    private StaffService staffService;

    /**
     * 根据名字查询员工
     * @param name
     * @return
     */
    @GetMapping("{name}")
    public Optional<Staff> describeByName(@PathVariable("name") String name){
        return Optional.empty();
    }

    /**
     * 新增员工
     * @param staff
     * @param branchIds
     * @return
     */
    @PostMapping("{branchIds}")
    public Optional<Result> createSatff(Staff staff, @PathVariable("branchIds") List<Integer> branchIds){
        return Optional.of(staffService.createStaff(staff, branchIds));
    }

    /**
     * 修改员工
     * @param staff
     * @param branchIds
     * @return
     */
    @PutMapping("{branchIds}")
    public Optional modifySatff(Staff staff,@PathVariable("branchIds") List<Integer> branchIds){
        return Optional.of(staffService.modifyStaff(staff,branchIds));
    }


    @DeleteMapping("{ids}")
    public Optional<Result> deleteSatff(@PathVariable("ids") List<Integer> ids ){
        return Optional.of(staffService.deleteStaffs(ids));
    }
}
